#
# Makefile for nvmutils
#
# Copyright (C) 2022 Leah Rowe <info@minifree.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

# config:
# ----------

CC=cc
FORCEC99=-std=c99
CFLAGS=-I. -Wall -Wextra -g $(FORCEC99)
NOLINKER=-c

# commands:
# ----------

all: clean nvmmac nvmcheck nvmfix nvmbrick nvmcp nvmswap

nvmmac: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o obj/lib/mac.o \
		obj/lib/word.o obj/nvmmac.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/mac.o obj/lib/word.o obj/nvmmac.o -o nvmmac

nvmcheck: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmcheck.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmcheck.o -o nvmcheck

nvmfix: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o obj/lib/word.o \
		obj/nvmfix.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmfix.o -o nvmfix

nvmbrick: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmbrick.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmbrick.o -o nvmbrick

nvmcp: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o obj/lib/word.o \
		obj/nvmcp.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmcp.o -o nvmcp

nvmswap: obj/lib/checksum.o obj/lib/version.o obj/lib/file.o obj/lib/word.o \
		obj/nvmswap.o

	$(CC) $(CFLAGS) obj/lib/checksum.o obj/lib/version.o obj/lib/file.o \
		obj/lib/word.o obj/nvmswap.o -o nvmswap

clean:
	rm -f nvmmac nvmcheck nvmfix nvmbrick nvmcp nvmswap obj/*.o obj/lib/*.o

# utils:
# ----------

obj/nvmmac.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmmac.c -o obj/nvmmac.o

obj/nvmcheck.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmcheck.c -o obj/nvmcheck.o

obj/nvmfix.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmfix.c -o obj/nvmfix.o

obj/nvmbrick.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmbrick.c -o obj/nvmbrick.o

obj/nvmcp.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmcp.c -o obj/nvmcp.o

obj/nvmswap.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/nvmswap.c -o obj/nvmswap.o

# libs:
# ----------

obj/lib/checksum.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/lib/checksum.c -o obj/lib/checksum.o

obj/lib/version.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/lib/version.c -o obj/lib/version.o

obj/lib/file.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/lib/file.c -o obj/lib/file.o

obj/lib/mac.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/lib/mac.c -o obj/lib/mac.o

obj/lib/word.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/lib/word.c -o obj/lib/word.o
